using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace AlphaWebsite.Models
{ 
    public class WeddingHouseholdsRepository : IWeddingHouseholdsRepository
    {
        AlphaWebsiteContext context = new AlphaWebsiteContext();

        public IQueryable<WeddingHouseholds> All
        {
            get { return context.WeddingHouseholds; }
        }

        public IQueryable<WeddingHouseholds> AllIncluding(params Expression<Func<WeddingHouseholds, object>>[] includeProperties)
        {
            IQueryable<WeddingHouseholds> query = context.WeddingHouseholds;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public WeddingHouseholds Find(System.Guid id)
        {
            return context.WeddingHouseholds.Find(id);
        }

        public void InsertOrUpdate(WeddingHouseholds weddinghouseholds)
        {
            if (weddinghouseholds.HouseholdID == default(System.Guid)) {
                // New entity
                weddinghouseholds.HouseholdID = Guid.NewGuid();
                context.WeddingHouseholds.Add(weddinghouseholds);
            } else {
                // Existing entity
                context.Entry(weddinghouseholds).State = EntityState.Modified;
            }
        }

        public void Delete(System.Guid id)
        {
            var weddinghouseholds = context.WeddingHouseholds.Find(id);
            context.WeddingHouseholds.Remove(weddinghouseholds);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IWeddingHouseholdsRepository : IDisposable
    {
        IQueryable<WeddingHouseholds> All { get; }
        IQueryable<WeddingHouseholds> AllIncluding(params Expression<Func<WeddingHouseholds, object>>[] includeProperties);
        WeddingHouseholds Find(System.Guid id);
        void InsertOrUpdate(WeddingHouseholds weddinghouseholds);
        void Delete(System.Guid id);
        void Save();
    }
}